import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;

@ManagedBean
@SessionScoped
public class IndexBean extends Users implements Serializable {
    InfoUbautUsers infoUbautUsers;
    SiteMap siteMap = new SiteMap();
    private String page = "template/welcome.xhtml";
    private int procentDostypa = 0;

    public void outPage() {

        page = "template/welcome.xhtml";
        procentDostypa = 0;

    }

    public void adminPage() {

        if (siteMap.testTipDostypa("admin", procentDostypa)) {
            page = "work/admin.xhtml";
        } else {
            page = "work/404.xhtml";
        }

    }

    public void managerPage() {

        if (siteMap.testTipDostypa("manager", procentDostypa)) {
            page = "work/manager.xhtml";
        } else {
            page = "work/404.xhtml";
        }

    }

    public void roomPage() {

        if (siteMap.testTipDostypa("guest", procentDostypa)) {
            page = "work/guest.xhtml";
        } else {
            page = "work/404.xhtml";
        }

    }

    public void animePage() {

        if (siteMap.testTipDostypa("anime", procentDostypa)) {
            page = "work/anime.xhtml";
        } else {
            page = "work/404.xhtml";
        }

    }

    public void authorizationPage() {
        if (siteMap.testTipDostypa("authorization", procentDostypa)) {
            page = "work/authorization.xhtml";
        } else {
            page = "work/404.xhtml";
        }

    }

    public void registrationPage() {
        if (siteMap.testTipDostypa("regictration", procentDostypa)) {
            page = "work/regictration.xhtml";
        } else {
            page = "work/404.xhtml";
        }

    }

    public void setPages() {

        page = "template/welcome.xhtml";
    }


    public String getPage() {
        return page;
    }

    private String login;
    private String password;


    public void authorization() {

        //insert();
        infoUbautUsers = mapUsers.get(login);
        if (infoUbautUsers == null) { // login neveren
            procentDostypa = 0;
        } else {
            if (infoUbautUsers.getPassword().equals(password)) {
                procentDostypa = infoUbautUsers.getTipDoctypa();
            } else {
                procentDostypa = 0; // parol ne veren
            }
        }


    }


    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getProcentDostypa() {
        return procentDostypa;
    }

    public void setProcentDostypa(int procentDostypa) {
        this.procentDostypa = procentDostypa;
    }
}
